﻿using System.Linq;
using System.Web.Mvc;
using QueryServices;
using Web.Extensions;

namespace Web.Controllers
{
    public class SectionController : Controller
    {
        private readonly ISectionQueryService _queryService;

        public SectionController(ISectionQueryService queryService)
        {
            _queryService = queryService;
        }

        [HttpGet]
        public ActionResult Index(string sectionId)
        {
            var sections = _queryService.FindAll();
            return PartialView("SectionNavbar", sections.Select(x => x.ToViewModel(sectionId)));
        }
        [HttpGet]
        public ActionResult GetAll()
        {
            return Json(new
            {
                success = true,
                data = _queryService.FindAll()
            }, JsonRequestBehavior.AllowGet);
        }
    }
}